/*
 * Copyright (c) 2019 DawnFramework. All Rights Reserved.
 * Licensed under the MIT (LICENSE) license.
 */

package org.dawn.common.service.service;

import org.dawn.common.core.except.IError;

import java.util.Collection;

/**
 * @author Willard Hu on 2019-05-10.
 */
public class ResponseBuilder {

    public static ServiceResponse succBase() {
        ServiceResponse resp = new ServiceResponse();
        resp.initSuccessData();
        return resp;
    }

    public static ServiceResponse failBase(IError<Integer> err) {
        ServiceResponse resp = new ServiceResponse();
        resp.initFailedData(err);
        return resp;
    }

    public static <T> ServiceTSingleResponse<T> succTSingle(T value) {
        ServiceTSingleResponse<T> resp = new ServiceTSingleResponse<>();
        resp.initSuccessData();
        resp.setValue(value);
        return resp;
    }

    public static <T> ServiceTSingleResponse<T> failTSingle(IError<Integer> err) {
        ServiceTSingleResponse<T> resp = new ServiceTSingleResponse<>();
        resp.initFailedData(err);
        return resp;
    }

    public static <T> ServiceTMultiResponse<T> succTMulti(Collection<T> values) {
        ServiceTMultiResponse<T> resp = new ServiceTMultiResponse<>();
        resp.initSuccessData();
        resp.setValues(values);
        return resp;
    }

    public static <T> ServiceTMultiResponse<T> failTMulti(IError<Integer> err) {
        ServiceTMultiResponse<T> resp = new ServiceTMultiResponse<>();
        resp.initFailedData(err);
        return resp;
    }

    public static <T> ServiceTPageResponse<T> succTPage(int page,
                                                        int rows,
                                                        Collection<T> values,
                                                        int totalCount) {
        ServiceTPageResponse<T> resp = new ServiceTPageResponse<>();
        resp.initSuccessedData(resp, page, rows, totalCount);
        resp.setValues(values);
        return resp;
    }

    public static <T> ServiceTPageResponse<T> failTPage(IError<Integer> err) {
        ServiceTPageResponse<T> resp = new ServiceTPageResponse<>();
        resp.initFailedData(err);
        return resp;
    }
}
